package com.zxcrm.web.controller.zxcrm;

import com.zxcrm.common.annotation.Log;
import com.zxcrm.common.core.controller.BaseController;
import com.zxcrm.common.core.domain.AjaxResult;
import com.zxcrm.common.core.page.TableDataInfo;
import com.zxcrm.common.enums.BusinessType;
import com.zxcrm.common.utils.poi.ExcelUtil;
import com.zxcrm.zxcrm.domain.ZxcrmProduct;
import com.zxcrm.zxcrm.service.IZxcrmProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品Controller
 * 
 * @author xu
 * @date 2025-07-09
 */
@RestController
@RequestMapping("/zxcrm/product")
public class ZxcrmProductController extends BaseController
{
    @Autowired
    private IZxcrmProductService zxcrmProductService;

    /**
     * 查询产品列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZxcrmProduct zxcrmProduct)
    {
        startPage();
        List<ZxcrmProduct> list = zxcrmProductService.selectZxcrmProductList(zxcrmProduct);
        return getDataTable(list);
    }

    /**
     * 查询产品列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(ZxcrmProduct zxcrmProduct)
    {
        List<ZxcrmProduct> list = zxcrmProductService.selectZxcrmProductList(zxcrmProduct);
        return AjaxResult.success(list);
    }

    /**
     * 导出产品列表
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:export')")
    @Log(title = "产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxcrmProduct zxcrmProduct)
    {
        List<ZxcrmProduct> list = zxcrmProductService.selectZxcrmProductList(zxcrmProduct);
        ExcelUtil<ZxcrmProduct> util = new ExcelUtil<ZxcrmProduct>(ZxcrmProduct.class);
        util.exportExcel(response, list, "产品数据");
    }

    /**
     * 获取产品详细信息
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(zxcrmProductService.selectZxcrmProductById(productId));
    }

    /**
     * 新增产品
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:add')")
    @Log(title = "产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxcrmProduct zxcrmProduct)
    {
        return toAjax(zxcrmProductService.insertZxcrmProduct(zxcrmProduct));
    }

    /**
     * 修改产品
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:edit')")
    @Log(title = "产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxcrmProduct zxcrmProduct)
    {
        return toAjax(zxcrmProductService.updateZxcrmProduct(zxcrmProduct));
    }

    /**
     * 删除产品
     */
    @PreAuthorize("@ss.hasPermi('zxcrm:product:remove')")
    @Log(title = "产品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(zxcrmProductService.deleteZxcrmProductByIds(productIds));
    }
}
